package com.zb.controller;


import com.zb.entity.dto.RoleDto;
import com.zb.entity.dto.RoleSelect;
import com.zb.exception.RegisterException;
import com.zb.result.Result;
import com.zb.service.ZjAdmRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 后台角色表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-07-07
 */
@Api(tags = "角色类接口")
@RestController
@RequestMapping("/role")
public class ZjAdmRoleController {
    @Autowired
    private ZjAdmRoleService admRoleService;

    @ApiOperation("添加或修改角色")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid RoleDto roleDto) throws RegisterException {
        admRoleService.add(roleDto);
        return Result.success(null == roleDto.getId()? "添加角色成功！" : "修改角色成功！");
    }


    @ApiOperation(value = "角色列表查询")
    @PostMapping("/getList")
    public Result getList(@RequestBody RoleSelect roleSelect) {
        Map<String, Object> result = admRoleService.getList(roleSelect);
        return Result.success("获取角色列表成功").data(result);
    }


}
